//
//  ViewController.m
//  06_UINavigationController
//
//  Created by li cheng on 16/7/21.
//  Copyright © 2016年 li cheng. All rights reserved.
//

#import "ViewController.h"
#import "PushViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    // 1.title 标题, 告诉用户, 我这个视图控制器是干嘛的
    self.title = @"什么什么情况";
    self.navigationItem.title = @"XXXXXXXXXXX";
    // 2.titleView 标题视图
    UISegmentedControl *segment = [[UISegmentedControl alloc] initWithItems:@[@"十大", @"沙发"]];
    segment.frame = CGRectMake(100, 100, 150, 44);
    // 标题视图, 修改x, y对视图本身没有影响
    self.navigationItem.titleView = segment;
    // 3.
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"回去" style:UIBarButtonItemStylePlain target:self action:@selector(comeBack:)];
    // 4.
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(add:)];
    // 5.
    UIBarButtonItem *barButtonItemTitle = [[UIBarButtonItem alloc] initWithTitle:@"bbbb" style:UIBarButtonItemStylePlain target:self action:@selector(comeBack:)];
    UIBarButtonItem *barButtonItemSystemItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemPlay target:self action:@selector(add:)];
    self.navigationItem.leftBarButtonItems = @[barButtonItemTitle, barButtonItemSystemItem, barButtonItemSystemItem, barButtonItemTitle];
    // 6. rightBarButtonItems 数组
    // barButtonItems数组中放1-2个Item为最优
    // 7. 隐藏navgationBar YES 隐藏, NO, 不隐藏,
    // 俩句等效
    self.navigationController.navigationBarHidden = NO;
    self.navigationController.navigationBar.hidden = NO;
    // 8. navgationBar的背景样式, 默认为 Default
    self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
    // 9.navigation的背景颜色
//    self.navigationController.navigationBar.backgroundColor = [UIColor redColor];
    // 10.barTintColor
//    self.navigationController.navigationBar.barTintColor = [UIColor redColor];
    // 11. 导航栏元素的颜色 titncolor
//    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    // 12.
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    button.frame = CGRectMake(0, 0, 200, 200);
    [self.view addSubview:button];
    [button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
    button.backgroundColor = [UIColor blueColor];
    // 设置为YES时, self.view坐标系从原点开始
    // 设置为NO时, self.view坐标原点从64开始
    self.navigationController.navigationBar.translucent = YES;
    // 13. 改变坐标效果, 与translucent为NO时的效果一样
    self.edgesForExtendedLayout = UIRectEdgeNone;
}

- (void)buttonClicked:(UIButton *)button{
    // 视图控制器入栈
    [self.navigationController pushViewController:[[PushViewController alloc] init] animated:YES];
}




- (void)comeBack:(UIBarButtonItem *)barButtonItem{
    NSLog(@"返回");
}

- (void)add:(UIBarButtonItem *)barButtonItem{
    NSLog(@"添加");
}





- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
